package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.constant.MessageConstant;
import com.atguigu.entity.PageResult;
import com.atguigu.entity.QueryPageBean;
import com.atguigu.entity.Result;

import com.atguigu.pojo.TravelGroup;
import com.atguigu.service.TravelGroupService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Eric
 * @Create 2020-09-16  10:26
 * @Version project-workspace-0912
 **/
@RestController
@RequestMapping("/travelgroup")
public class TravelgroupController {

    @Reference
    private TravelGroupService travelGroupService;

    @RequestMapping("/add")
    public Result add(@RequestBody TravelGroup travelGroup,Integer[] travelItemIds)
    {
        travelGroupService.add(travelGroup,travelItemIds);
        return new Result(true, MessageConstant.ADD_TRAVELGROUP_SUCCESS);
    }

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean)
    {
        //查询条件 当前页 pageSize 查询条件
        PageResult pageResult =  travelGroupService.findPage(queryPageBean);
        return pageResult;
    }

    @RequestMapping("/findById")
    public Result findById( Integer id)
    {
       TravelGroup lists = travelGroupService.findById(id);
        return new Result(true,MessageConstant.QUERY_TRAVELGROUP_SUCCESS,lists);
    }

    @RequestMapping("/findAll")
    public Result findAll()
    {
        List<TravelGroup> lists = travelGroupService.findAll();
        return new Result(true,MessageConstant.QUERY_TRAVELGROUP_SUCCESS,lists);
    }

    @RequestMapping("/findTravelItemIdByTravelgroupId")
    public List findTravelItemIdByTravelgroupId(Integer id)
    {
        List<Integer> lists = travelGroupService.findTravelItemIdByTravelgroupId(id);
        return lists;
    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody TravelGroup travelGroup,Integer[] travelItemIds)
    {
        travelGroupService.edit(travelGroup,travelItemIds);
        return new Result(true,MessageConstant.EDIT_TRAVELGROUP_SUCCESS);
    }

}
